package cn.yunyichina.provider.base.service.impl;

import cn.yunyichina.provider.base.dao.OrderDao;
import cn.yunyichina.provider.base.dao.OrderExceptionDao;
import cn.yunyichina.provider.base.dao.OrderListDao;
import cn.yunyichina.provider.base.entity.Order;
import cn.yunyichina.provider.base.entity.OrderException;
import cn.yunyichina.provider.base.entity.OrderExt;
import cn.yunyichina.provider.base.entity.OrderList;
import cn.yunyichina.provider.framework.dubbo.service.CacheService;
import cn.yunyichina.provider.framework.dubbo.service.DrugService;
import cn.yunyichina.provider.framework.exception.CallException;
import cn.yunyichina.provider.framework.page.PageInfo;
import cn.yunyichina.provider.framework.utils.UUIDUtil;
import cn.yunyichina.provider.iface.entity.ErrorCodeDefine;
import cn.yunyichina.provider.iface.entity.base.OrderExtVo;
import cn.yunyichina.provider.iface.entity.common.Response;
import cn.yunyichina.provider.iface.entity.common.ResponseObject;
import cn.yunyichina.provider.iface.entity.drug.DeliveryVo;
import cn.yunyichina.utils.commons.DateUtils;
import cn.yunyichina.utils.commons.IDUtils;
import cn.yunyichina.utils.convert.JsonUtils;
import com.alibaba.dubbo.common.utils.CollectionUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by JoeZ on 2016/9/19.
 */
@Service
public class OrderServiceImpl extends BaseSelectService {

    private static final Logger logger = LoggerFactory.getLogger(OrderServiceImpl.class);

    @Autowired
    private OrderDao orderDao;

    @Autowired
    private OrderExceptionDao orderExceptionDao;

    public ResponseObject getOrderRecord(String data) {

        logger.info("查询订单记录data={}", data);
        ResponseObject response = new ResponseObject();
        OrderExtVo orderExtVo = JsonUtils.parseObject(data, OrderExtVo.class);
        if (StringUtils.isBlank(orderExtVo.getUserId()) || StringUtils.isBlank(orderExtVo.getPlatformOrgAppCode()) || orderExtVo.getOrderType() == null) {
            response.setResultCodeAndMessage("1001", "参数缺失请校验");
            return response;
        }

        Map<String, Object> queryOderMap = new HashMap<String, Object>();
        queryOderMap.put("orgCode", orderExtVo.getOrgCode());
        queryOderMap.put("userId", orderExtVo.getUserId());
        queryOderMap.put("orderType", orderExtVo.getOrderType());
        queryOderMap.put("platformOrgAppCode", orderExtVo.getPlatformOrgAppCode());
        queryOderMap.put("pageSize", orderExtVo.getPageSize());
        queryOderMap.put("pageNum", orderExtVo.getPageNum());
        List<Integer> payStatus = new ArrayList<>();
        List<Integer> orderStatus = new ArrayList<>();

        if (orderExtVo.getOrderType() != null && orderExtVo.getOrderType() == 10) {
            payStatus.add(3);
            payStatus.add(5);
            payStatus.add(7);

            orderStatus.add(2);
            orderStatus.add(3);
            orderStatus.add(7);
            queryOderMap.put("payStatus", payStatus);
            queryOderMap.put("orderStatus", orderStatus);
        }

        if (orderExtVo.getOrderType() != null && orderExtVo.getOrderType() == 3) {
            orderStatus.add(3);
            orderStatus.add(4);
            orderStatus.add(5);
            orderStatus.add(6);
            orderStatus.add(7);
            orderStatus.add(8);
            queryOderMap.put("orderStatus",orderStatus);
        }

        if (orderExtVo.getOrderType() != null && orderExtVo.getOrderType() == 1) {
            orderStatus.add(3);
            orderStatus.add(4);
            orderStatus.add(5);
            queryOderMap.put("orderStatus",orderStatus);
        }


        if (orderExtVo.getOrderDays() != null) {
            String createdTime = DateUtils.getDayForDate(new Date(), orderExtVo.getOrderDays()) + " 00:00:00";
            queryOderMap.put("createdTime", createdTime);
        }

        List<Order> orderList = orderDao.selectOrderRecordList(queryOderMap);
        Long dataCount = orderDao.selectCountOrderRecordList(queryOderMap);
        Map<String, Object> resultMap = new HashMap<String, Object>();
        resultMap.put("dataCount", dataCount);
        resultMap.put("datas", orderList);
        response.setResultCodeAndMessageAndResult("0", "成功", resultMap);
        logger.info("查询订单记录出参response={}",new Object[]{JsonUtils.toJsonString(response)});
        return response;
    }

    /**
     * 根据订单号查询订单
     *
     * @param data order_no
     * @return
     */
    public Response findOrder(String data) {

        Response response = new Response();
        Order order = this.getOrderByOrderNo(data);
        if (order != null) {
            response.setResult(JsonUtils.toJsonString(order));
            response.setResultCodeAndMessage("0", "查询成功!");
        } else {
            response.setResult(null);
            response.setResultCodeAndMessage("1001", "查无结果");
        }
        return response;

    }


    /**
     * 根据条件查询订单
     *
     * @param data data
     * @return
     * @interface yyt.base.order.list.get
     */
    public Response getOrderList(String data) {
        Response response = new Response();
        OrderExt order = JsonUtils.parseObject(data, OrderExt.class);
        List<Order> orderList = orderDao.select(order);
        if (orderList.size() > 0) {
            response.setResult(JsonUtils.toJsonString(orderList));
            response.setResultCodeAndMessage("0", "查询成功!");
        } else {
            response.setResult(orderList.toString());
            response.setResultCodeAndMessage("1001", "查无结果");
        }
        return response;

    }


    @Autowired
    private OrderListDao orderListDao;

    private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    /**
     * 列表查询
     * yyt.base.order.list
     *
     * @param strJson
     * @return
     */
    public List<Order> listOrder(String strJson) {
        return listEntity(strJson, Order.class, orderDao);

    }

    /**
     * 列表查询（带分页信息）
     * yyt.base.order.for.page.list
     *
     * @param datas
     * @return
     */
    public ResponseObject listOrderForPage(String datas) {
        ResponseObject response = new ResponseObject();
        Map<String, Object> result = new HashMap<>();
        List<Order> orders = new ArrayList<Order>();
        List<String> orderColumns = new ArrayList<String>();
        PageInfo pageInfo = null;
        Order order = JsonUtils.parseObject(datas, Order.class);
        if (order != null) {
            pageInfo = JsonUtils.parseObject(datas, PageInfo.class);
            orderColumns.add("CREATED_TIME");
            orders = orderDao.select(order, orderColumns, false, pageInfo);
        }

        Map<String, String> map = JSON.parseObject(datas, Map.class);
        String pageNum = map.get("page_num");
        String pageSize = map.get("page_size");

        if (StringUtils.isNotBlank(pageNum) && StringUtils.isNotBlank(pageSize)) {
            if (pageInfo != null) {
                long totalSize = orderDao.selectCount(order);
                pageInfo.setTotal(totalSize);
                pageInfo.setPages((pageInfo.getTotal().intValue() + pageInfo.getPageSize() - 1) / pageInfo.getPageSize());
            }
            result.put("page_info", pageInfo);
        }

        result.put("list", orders);

        response.setResultObject(JsonUtils.toJsonString(result));
        response.setResultCodeAndMessage("0", "查询成功!");

        return response;
    }


    /**
     * 参数非空验证
     *
     * @param param
     * @param fieldNames
     */
    private void validParam(JSONObject param, String fieldNames) {
        if (StringUtils.isNotEmpty(fieldNames)) {
            String[] arrFieldName = fieldNames.split(",");
            for (String fieldName : arrFieldName) {
                if (StringUtils.isBlank(param.getString(fieldName.trim()))) {
                    throw new CallException(ErrorCodeDefine.ORDER_PARAM, "参数异常" + fieldName.trim());
                }
            }
        }
    }

    /**
     * 列表查询(增城人民医院自助机)
     * yyt.base.order.out.list
     *
     * @param strJson
     * @return
     */
    public List<JSONObject> listOrderOut(String strJson) {
        logger.info(strJson);
        JSONObject param = JsonUtils.parseObject(strJson);

        validParam(param, "hospital_code,pay_begin_time,pay_end_time");
        param.put("supply_org_code", param.getString("hospital_code"));
        param.put("begin_pay_time", param.getString("pay_begin_time"));
        param.put("end_pay_time", param.getString("pay_end_time"));
        if (param.containsKey("pat_card_no")) {
            param.put("medical_card_no", param.getString("pat_card_no"));
        }

        if (param.containsKey("pat_name")) {
            param.put("user_name", param.getString("pat_name"));
        }

        if (param.containsKey("pat_mobile")) {
            param.put("user_mobile", param.getString("pat_mobile"));
        }

        List<Order> listOrder = listEntity(JsonUtils.toJsonString(param), Order.class, orderDao);
        if (CollectionUtils.isNotEmpty(listOrder)) {
            List<JSONObject> listJson = new ArrayList<>();
            for (Order order : listOrder) {
                JSONObject jsonOrder = JsonUtils.parseObject(order);
                jsonOrder.put("hospital_id", order.getOrgId());
                jsonOrder.put("hospital_code", order.getOrgCode());
                jsonOrder.put("hospital_name", order.getOrgName());
                jsonOrder.put("pat_id", order.getUserId());
                jsonOrder.put("pat_name", order.getUserName());
                jsonOrder.put("pat_mobile", order.getUserMobile());
                jsonOrder.put("pat_card_type", order.getMedicalCardType());
                jsonOrder.put("pat_card_no", order.getMedicalCardNo());
                jsonOrder.put("pat_id_type", order.getIdCardType());
                jsonOrder.put("pat_id_no", order.getIdCardNo());
                jsonOrder.put("pat_address", order.getUserAddress());
                jsonOrder.put("pat_sex", order.getUserSex());

                jsonOrder.remove("org_id");
                jsonOrder.remove("org_code");
                jsonOrder.remove("org_name");
                jsonOrder.remove("user_id");
                jsonOrder.remove("user_name");
                jsonOrder.remove("user_mobile");
                jsonOrder.remove("medical_card_type");
                jsonOrder.remove("medical_card_no");
                jsonOrder.remove("id_card_type");
                jsonOrder.remove("id_card_no");
                jsonOrder.remove("user_address");
                jsonOrder.remove("user_sex");

                listJson.add(jsonOrder);
            }
            return listJson;

        } else {
            return new ArrayList<JSONObject>();
        }

    }

    /**
     * 根据订单ID，查询订单的子项列表
     * yyt.base.order.list.list
     *
     * @param data json对象，order_id
     * @return
     */
    public List<OrderList> listOrderList(String data) {
        JSONObject jsonObj = JsonUtils.parseObject(data);

        if (!StringUtils.isBlank(jsonObj.getString("hospital_code"))) {
            jsonObj.put("supply_org_code", jsonObj.getString("hospital_code"));
        }


        if (!StringUtils.isBlank(jsonObj.getString("app_id"))) {
            jsonObj.put("pay_app_id", jsonObj.getString("app_id"));
        }

        return listOrderItem(jsonObj.getString("order_no"));

    }


    /**
     * 获得订单
     * yyt.base.order.by.orderno.get
     *
     * @param data orderNo
     * @return
     */
    public Order getOrderByOrderNo(String data) {
        OrderExt order = null;
        if (data.trim().startsWith("{")) {
            order = JsonUtils.parseObject(data, OrderExt.class);
        } else {
            order = new OrderExt();
            order.setOrderNo(data);
        }
        Order returnOrder = orderDao.selectByOrderNo(order.getOrderNo());

        if (returnOrder != null) {
            List<OrderList> listItem = listOrderItem(order.getOrderNo());
            returnOrder.setListItem(listItem);

            String json = listOrderBusinessExpansion(returnOrder.getOrderNo(), returnOrder.getOrderType());
            returnOrder.setBusinessExpansion(json);
        }

        return returnOrder;

    }

    /**
     * 根据订单ID，查询订单的子项列表
     * yyt.base.order.item.list
     *
     * @param orderNo 订单号
     * @return
     */
    public List<OrderList> listOrderItem(String orderNo) {
        if (StringUtils.isNotBlank(orderNo) && orderNo.trim().startsWith("{")) {
            Order order = JsonUtils.parseObject(orderNo, OrderExt.class);
            orderNo = order.getOrderNo();
        }
        List<OrderList> listOrderItem = orderListDao.queryByOrderNo(orderNo);
        return listOrderItem;

    }

    /**
     * 根据订单ID，查询订单的子项列表(增城人民医院自助机)
     * yyt.base.order.item.out.list
     *
     * @param strJson 订单号
     * @return
     */
    public Response listOrderItemOut(String strJson) {
        Response response = new Response();
        logger.info(strJson);
        JSONObject param = JsonUtils.parseObject(strJson);
        String orderNo = param.getString("order_no");
        if (StringUtils.isEmpty(orderNo)) {
            throw new CallException(ErrorCodeDefine.ORDER_PARAM, "订单号参数缺失");
        }
        List<OrderList> listOrderItem = orderListDao.queryByOrderNo(orderNo);
        if (CollectionUtils.isNotEmpty(listOrderItem)) {
            List<JSONObject> listJson = new ArrayList<>();
            for (OrderList item : listOrderItem) {
                if (item.getExtraParams() != null) {
                    Map<String, String> extraMap = JsonUtils.parseObject(item.getExtraParams(), Map.class);
                    if (extraMap != null) {
                        if ("0".equals(extraMap.get("can_pay"))) {
                            logger.info("存在不可缴费项目，订单号： " + orderNo);
                            response.setResultCodeAndMessage("1001", "存在不可缴费项目,不能线上缴费，请到窗口缴费");
                            return response;
                        }
                    }
                }
                JSONObject jsonItem = JsonUtils.parseObject(item);

                jsonItem.put("item_id", item.getGoodsId());
                jsonItem.put("item_name", item.getGoodsName());
                jsonItem.put("item_spec", item.getGoodsSpec());
                jsonItem.put("item_unit", item.getGoodsUnit());
                jsonItem.put("item_price", item.getGoodsPrice());
                jsonItem.put("item_qty", item.getGoodsQty());
                jsonItem.put("tot_item_money", item.getTotGoodsMoney());
                jsonItem.put("tot_real_item_money", item.getTotRealGoodsMoney());

                jsonItem.remove("goods_id");
                jsonItem.remove("goods_name");
                jsonItem.remove("goods_spec");
                jsonItem.remove("goods_unit");
                jsonItem.remove("goods_price");
                jsonItem.remove("goods_qty");
                jsonItem.remove("tot_goods_money");
                jsonItem.remove("tot_real_goods_money");

                listJson.add(jsonItem);

            }
//			return listJson;
            response.setResult(JsonUtils.toJsonString(listJson));
            response.setResultCodeAndMessage("0", "成功");
            return response;
        }
        response.setResultCodeAndMessage("1002", "查无数据，请稍后再查");
        return response;
    }

    /**
     * 新增订单
     * yyt.base.order.add
     *
     * @param data trade_type 交易类型，1支付，2退款
     */
    public Order addOrder(String data) {

        try {
            logger.debug("addOrder入参:" + data);
            OrderExt order = JsonUtils.parseObject(data, OrderExt.class);
            JSONObject jsonParam = JsonUtils.parseObject(data);
            if (!jsonParam.containsKey("trade_type")) {
                jsonParam.put("trade_type", 1);
            }
            if (StringUtils.isBlank(order.getId())) {
                order.setId(IDUtils.getUUID32());
            }
            if (StringUtils.isBlank(order.getOrderNo())) {
                order.setOrderNo(CacheService.generateOrderNum(order.getOrderType(), jsonParam.getIntValue("trade_type")));
            }

            order.setCreatedTime(simpleDateFormat.format(new Date()));
            order.setUpdateTime(simpleDateFormat.format(new Date()));

            logger.debug("插入数据库的数据Order:" + JsonUtils.toJsonString(order));
            orderDao.insert(order);

            //订单项
            List<OrderList> listOrderItem = order.getListItem();
            logger.debug("入参的订单项数据：" + JsonUtils.toJsonString(listOrderItem));
            if (listOrderItem != null && listOrderItem.size() > 0) {
                for (OrderList item : listOrderItem) {
                    item.setOrderId(order.getId());
                    item.setOrderNo(order.getOrderNo());
                    item.setId(UUIDUtil.get32UUID());
                    item.setCreatedTime(order.getCreatedTime());
                }
                logger.debug("要插入的订单项数据：" + JsonUtils.toJsonString(listOrderItem));
                orderListDao.batchInsert(listOrderItem);
            }

            return order;
        } catch (Exception e) {
            logger.error("新增订单错误" + e.toString());
            throw new CallException(ErrorCodeDefine.ORDER_COMMON, "新增订单错误", e);
        }


    }

    /**
     * 更新订单数据
     * yyt.base.order.update
     * 如果包含了订单项，则会删除原来的所有订单项，然后执行新增订单项的操作
     *
     * @param data
     */
    public Order updateOrder(String data) {

        try {
            logger.debug("updateOrder入参:" + data);
            OrderExt order = JsonUtils.parseObject(data, OrderExt.class);
            if (StringUtils.isBlank(order.getId())) {
                Order orderDb = orderDao.selectByOrderNo(order.getOrderNo());
                if (orderDb == null) {
                    throw new CallException(ErrorCodeDefine.ORDER_NO_INVALID, "没有指定订单号的订单记录");
                }
                order.setId(orderDb.getId());
            }

            logger.debug("要修改的updateOrder:" + JsonUtils.toJsonString(order));
            orderDao.update(order);

            List<OrderList> listOrderItem = order.getListItem();

            logger.debug("订单项数据入参:" + JsonUtils.toJsonString(listOrderItem));

            if (listOrderItem != null && listOrderItem.size() > 0) {

                //删除原先所有订单项
                orderListDao.deleteByOrderNo(order.getOrderNo());

                for (OrderList item : listOrderItem) {
                    item.setOrderId(order.getId());
                    item.setOrderNo(order.getOrderNo());
                    item.setId(UUID.randomUUID().toString().replaceAll("-", ""));
                    item.setCreatedTime(order.getCreatedTime());
                }

                //新增订单项
                logger.debug("要修改的订单项数据:" + JsonUtils.toJsonString(listOrderItem));
                orderListDao.batchInsert(listOrderItem);
            }

            return order;
        } catch (Exception e) {
            logger.error("修改订单错误" + e.toString());
            throw new CallException(ErrorCodeDefine.ORDER_COMMON, "修改订单错误", e);
        }
    }

    /**
     * 修改订单状态
     * yyt.base.order.status.change
     *
     * @param data order_no,order_status
     */
    public void changeOrderStatus(String data) {

        OrderExt order = JsonUtils.parseObject(data, OrderExt.class);
        if (order.getOrderStatus() == null || StringUtils.isBlank(order.getOrderNo())) {
            throw new CallException(ErrorCodeDefine.ORDER_PARAM, "参数值不全");
        }

        changeOrderStatus(order.getOrderNo(), order.getOrderStatus());

    }

    /**
     * 修改订单状态
     *
     * @param orderNo
     * @param orderStatus
     */
    public void changeOrderStatus(String orderNo, Short orderStatus) {
        orderDao.changeOrderStatus(orderNo, orderStatus);

    }

    public void addOrderOut(String data) {
        logger.info("addOrderOut, data =" + data);
        List<OrderExt> order = JsonUtils.parseArray(data, OrderExt.class);
        for (OrderExt orderExt : order) {
            orderDao.insert(orderExt);
        }
    }

    public void addOrderListOut(String data) {
        logger.info("addOrderListOut, data =" + data);
        List<OrderList> orderlist = JsonUtils.parseArray(data, OrderList.class);
        if (orderlist != null && orderlist.size() > 0) {
            orderListDao.batchInsert(orderlist);
        }
    }

    public Response getOrderByOrderNoOut(String data) {
        Response response = new Response();
        OrderExt order = JsonUtils.parseObject(data, OrderExt.class);
        if (StringUtils.isBlank(order.getOrderNo())) {
            response.setResult(null);
            response.setResultCodeAndMessage("1001", "查无结果");
            return response;
        }
        List<Order> listOrder = orderDao.select(order);
        Order returnOrder = new Order();
        if (listOrder != null && listOrder.size() > 0) {
            returnOrder = listOrder.get(0);
            if (returnOrder != null) {
                List<OrderList> listItem = listOrderItem(order.getOrderNo());
                returnOrder.setListItem(listItem);
            }
            response.setResult(JsonUtils.toJsonString(returnOrder));
            response.setResultCodeAndMessage("0", "查询成功!");
        } else {
            response.setResult(null);
            response.setResultCodeAndMessage("1001", "查无结果");
        }
        return response;
    }

    public Response queryOrderExceptionByOrderNo(String data) {
        Response response = new Response();
        try {
            logger.info("根据订单号查询异常订单原始入参 data ={}", new Object[]{data});
            JSONObject jsonObject = JSONObject.parseObject(data);
            String orderNo = jsonObject.getString("order_no");
            if (StringUtils.isBlank(orderNo)) {
                response.setResultCodeAndMessage("1001", "订单号不能为空");
                return response;
            }
            OrderException order = orderExceptionDao.selectByOrderNo(orderNo);
            response.setResultCodeAndMessageAndResult("0", "成功", JsonUtils.toJsonString(order));

        } catch (Exception e) {
            logger.error("查询订单异常", e);
            response.setResultCodeAndMessage("-1", "查询订单异常");
        }
        logger.info("根据订单号查询异常订单返回 response ={}", new Object[]{JsonUtils.toJsonString(response)});
        return response;
    }

    public void addOrderException(String data) {
        logger.info("addOrderException, data =" + data);
        OrderException order = JsonUtils.parseObject(data, OrderException.class);
        orderExceptionDao.insert(order);
    }

    public void updateOrderException(String data) {
        logger.info("updateOrderException, data =" + data);
        OrderException order = JsonUtils.parseObject(data, OrderException.class);
        orderExceptionDao.update(order);
    }

    public OrderException getOrderExceptionByOrderNo(String data) {
        OrderException order = JsonUtils.parseObject(data, OrderException.class);
        return orderExceptionDao.selectByOrderNo(order.getOrderNo());
    }

    public List<OrderException> listOrderExceptions(String data) {
        OrderException order = JsonUtils.parseObject(data, OrderException.class);
        return orderExceptionDao.select(order);
    }

    // 获取未处理异常单
    public List<OrderException> listOrderExceptionUntreated(String data) {
        return orderExceptionDao.selectUntreatedOrderExceptions();
    }


    /**
     * 订单列表数据查询
     * yyt.base.order.datas.list
     *
     * @param json
     * @return
     */
    public Response listOrderDatas(String json) {
        Response response = new Response();
        Order order = JsonUtils.parseObject(json, Order.class);
        List<Order> listOrder = orderDao.select(order);

        if (listOrder.size() > 0) {
            response.setResultCodeAndMessageAndResult(Response.SUCCESS_CODE, Response.SUCCESS_MESSAGE, JsonUtils.toJsonString(listOrder));
        } else {
            response.setResultCodeAndMessage(Response.FAILURE_CODE, Response.FAILURE_MESSAGE);
        }
        return response;
    }


    /**
     * 订单列表数据查询，根据订单号list
     * yyt.base.order.by.order.nos.list
     *
     * @param data
     * @return
     */
    public Response listOrderByOrderNos(String data) {
        Response response = new Response();
        Map<String, String> map = JsonUtils.parseObject(data, Map.class);
        String orderList = map.get("order_list");
        if (StringUtils.isBlank(orderList)) {
            response.setResultCodeAndMessage("1001", "orderlist can not be null");
            return response;
        }
        String[] orderNos = orderList.split(",");
        List<Order> listOrder = orderDao.selectByOrderNos(Arrays.asList(orderNos));

        if (listOrder.size() > 0) {
            response.setResultCodeAndMessageAndResult(Response.SUCCESS_CODE, Response.SUCCESS_MESSAGE, JsonUtils.toJsonString(listOrder));
        } else {
            response.setResultCodeAndMessage("1001", "查无结果");
        }
        return response;
    }

    /**
     * 订单列表数据查询，根据医生编码、挂号日期查询停诊订单
     * yyt.base.order.by.doctors.list
     *
     * @param data
     * @return
     */
    public Response listOrderByDoctors(String data) {
        Response response = new Response();
        Map<String, String> map = JsonUtils.parseObject(data, Map.class);
        if (StringUtils.isBlank(map.get("org_code")) || StringUtils.isBlank(map.get("doctor_codes"))
                || StringUtils.isBlank(map.get("begin_schedule_time")) || StringUtils.isBlank(map.get("end_schedule_time"))
                || StringUtils.isBlank(map.get("doctor_condition"))) {
            response.setResultCodeAndMessage("1002", "查询入参错误");
            return response;
        }

        List<Order> listOrder = orderDao.listStopOrderByDoctors(map);

        if (listOrder.size() > 0) {
            response.setResultCodeAndMessageAndResult(Response.SUCCESS_CODE, Response.SUCCESS_MESSAGE, JsonUtils.toJsonString(listOrder));
        } else {
            response.setResultCodeAndMessage("1001", "查无结果");
        }
        return response;
    }

    /**
     * 获取订单表关联业务扩展信息
     * @param orderNo
     * @return
     */
    public String listOrderBusinessExpansion(String orderNo, Short orderType) {
        String returnJson  = "";
        try {
            //pbm
            if(orderType == 10){
                Map<String, String> queryMap = new HashMap<String, String>();
                queryMap.put("order_no", orderNo);
                queryMap.put("query_type", "auto");
                Response queryResponse = DrugService.callUnderlineFromInternal("yyt.drug.delivery.list", JsonUtils.toJsonString(queryMap));
                if("0".equals(queryResponse.getResultCode())){
                    Map<String, Object> result = new HashMap<>();
                    DeliveryVo vo = JsonUtils.parseObject(queryResponse.getResult(), DeliveryVo.class);
                    result.put("delivery", vo);
                    returnJson = JsonUtils.toJsonString(result);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return returnJson;
    }

    public static void main(String[] args) {
        List<String> ar = new ArrayList<String>();
        ar.add("A001");
        ar.add("A002");
    }
}
